import * as YvanUI from 'yvan-ui-wotu'
import {SimpleWidget} from "../widget/SimpleWidget";

interface Ref {
    t1: YvanUI.Text,
    t2: YvanUI.Text
}

const React = YvanUI.React
const {Card} = YvanUI.Antd
const Observer = YvanUI.Observer
const _ = YvanUI.lodash

export default class Simple2 extends YvanUI.Scope<void, Ref> {

    main = this.$$({
        f1: '',
        f2: '',
        suppliercode: '',
        suppliername: '',
        supplierprovince: '',
        suppliercity: '',
        supplierzip: '',
        suppliercontact: '',
        suppliertel: '',
        supplieraddress: '',
    })

    onRender() {
        window['biz'] = this
    }

    vjson = {
        title: '极简-查询框',
        items: [
            {
                view: 'form',
                debug: 'main',
                items: [
                    {
                        view: 'search',
                        label: '查找1',
                        bind: 'main.suppliername',
                        allowModify: true,
                        widget: SimpleWidget.define({
                            onOpen: () => {
                                console.log('simpleSearch.onOpen')
                                return {
                                    customercode: this.main.suppliercode,
                                    customername: this.main.suppliername,
                                    province: this.main.supplierprovince,
                                    city: this.main.suppliercity,
                                    zip: this.main.supplierzip,
                                    contact: this.main.suppliercontact,
                                    telephone: this.main.suppliertel,
                                    address: this.main.supplieraddress,
                                }
                            },
                            onClear: () => {
                                console.log('simpleSearch.onClear')
                                this.main.suppliercode = ''
                                this.main.suppliername = ''
                                this.main.supplierprovince = ''
                                this.main.suppliercity = ''
                                this.main.supplierzip = ''
                                this.main.suppliercontact = ''
                                this.main.suppliertel = ''
                                this.main.supplieraddress = ''
                            },
                            onConfirm: (data) => {
                                console.log('simpleSearch.onConfirm', data)
                                this.main.suppliercode = data.customercode
                                this.main.suppliername = data.customername
                                this.main.supplierprovince = data.province
                                this.main.suppliercity = data.city
                                this.main.supplierzip = data.zip
                                this.main.suppliercontact = data.contact
                                this.main.suppliertel = data.telephone
                                this.main.supplieraddress = data.address
                            }
                        })
                    },
                    {
                        view: 'search',
                        label: '查找2',
                        bind: 'main.f2',
                        widget: SimpleWidget.define({
                            bind: {
                                'main.suppliercode': 'customercode',
                                'main.f2': 'customername',
                                'main.supplierprovince': 'province',
                                'main.suppliercity': 'city',
                                'main.supplierzip': 'zip',
                                'main.suppliercontact': 'contact',
                                'main.suppliertel': 'telephone',
                                'main.supplieraddress': 'address',
                            }
                        })
                    },
                ]
            }
        ]
    }

}